﻿using System;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Windows;

using ManageSystemClient.HttpService;

using Microsoft.Extensions.DependencyInjection;

namespace ManageSystemClient
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private readonly IServiceProvider serviceProvider;

        public App()
        {
            var serviceCollection = new ServiceCollection();
            ConfigureService(serviceCollection);
            serviceProvider = serviceCollection.BuildServiceProvider();
        }

        private static void ConfigureService(IServiceCollection services)
        {
            var serviceTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.Namespace == typeof(HttpServiceBase).Namespace);
            foreach (var ser in serviceTypes)
            {
                services.AddSingleton(ser);
            }
            services.AddScoped<MainPage>()
                .AddScoped<LoginWindow>()
                .AddScoped<NaviWindow>();
        }

        private void Start(object _, StartupEventArgs __)
        {
            serviceProvider.GetRequiredService<LoginWindow>().Show();
        }
    }
}
